# -*- coding:utf8 -*-

import os
import Image

def dataAugmatation_folder(src_folder,res_folder):
    flag = 1
    for src_img in os.listdir(src_folder):
        src_img_path = src_folder + "\\" + src_img
        im = Image.open(src_img_path)
        im_90 = im.transpose(Image.ROTATE_90)
        im_180 = im.transpose(Image.ROTATE_180)
        im_270 = im.transpose(Image.ROTATE_270)

        res_img_path_0 = res_folder + "\\" + "0" + src_img
        res_img_path_90 = res_folder + "\\" + "90" + src_img
        res_img_path_180 = res_folder + "\\" + "180" + src_img
        res_img_path_270 = res_folder + "\\" + "270" + src_img

        im.save(res_img_path_0)
        im_90.save(res_img_path_90)
        im_180.save(res_img_path_180)
        im_270.save(res_img_path_270)

        flag += 1
        if flag%100 == 0:
            print "done:" + str(flag)

def dataAugmatation_single(src_img,res_folder):
        src_img_path = src_img
        im = Image.open(src_img_path)
        im_90 = im.transpose(Image.ROTATE_90)
        im_180 = im.transpose(Image.ROTATE_180)
        im_270 = im.transpose(Image.ROTATE_270)

        res_img_path_0 = res_folder + "\\" + "0" + src_img
        res_img_path_90 = res_folder + "\\" + "90" + src_img
        res_img_path_180 = res_folder + "\\" + "180" + src_img
        res_img_path_270 = res_folder + "\\" + "270" + src_img

        im.save(res_img_path_0)
        im_90.save(res_img_path_90)
        im_180.save(res_img_path_180)
        im_270.save(res_img_path_270)
def dataAugmatation_folder_flip(src_folder,res_folder):
    flag = 1
    for src_img in os.listdir(src_folder):
        src_img_path = src_folder + "\\" + src_img
        im = Image.open(src_img_path)
        im_flip = im.transpose(Image.FLIP_LEFT_RIGHT)

        res_img_path_0 = res_folder + "\\" + "0" + src_img
        res_img_path_flip = res_folder + "\\" + "flip" + src_img

        im.save(res_img_path_0)
        im_flip.save(res_img_path_flip)


        flag += 1
        if flag%100 == 0:
            print "done:" + str(flag)
if __name__ == '__main__':
    """
    dataAugmatation_folder("C:\\Users\\wuxiaomin\\Desktop\\arobei\\neg_new",\
                           "C:\\Users\\wuxiaomin\\Desktop\\arobei\\neg_new_aug")
    """
    dataAugmatation_folder_flip("C:\\Users\\wuxiaomin\\Desktop\\arobei\\positive_all_64",
                                "C:\\Users\\wuxiaomin\\Desktop\\arobei\\new\\data\\positive_all_64_aug")